#!/usr/bin/env python3
# -*- coding:utf-8 -*-
"""
@author:shengwei
@file:contextlib_py.py
@time:2018/2/26 002614:28
"""
from contextlib import contextmanager


class Query(object):
    def __init__(self, name):
        self.name = name

    def query(self):
        print('query info %s' % self.name)


@contextmanager
def create_query(name):
    print('Begin')
    q = Query(name)
    yield q
    print('End')


with create_query('bob') as q:
    q.query()
